<?php

/**
 * @Author: liu
 * @Date:   2017-11-23 16:34:09
 * @Last Modified by:   liu
 * @Last Modified time: 2017-11-23 18:27:04
 * 用于每天凌晨执行  取消所有未完成订单的余额支付 记录
 */
$api_service_path = __DIR__ . "/../../../api/";
ob_start();
require_once($api_service_path . "public/index.php");
ob_end_clean();

//取消 当前未完成的 服务单的余额支付记录
$op_arr=OrderPay::leftJoin("orders","orders.order_id","=","order_pay_record.order_id")->where('orders.status',1420)->where('orders.order_type',1)
->where('order_pay_record.status',1)->where('order_pay_record.pay_type',8)->select("order_pay_record.order_id","order_pay_record.id")->get();
foreach ($op_arr as $_op) {
	OrderPay::cancel($_op->order_id,$_op->id,0,"service");
}

//取消 当前未完成的  零售单的 余额支付记录
$op_arr=OrderPay::leftJoin("orders","orders.order_id","=","order_pay_record.order_id")->where('orders.status',1411)->where('orders.order_type',2)
->where('order_pay_record.status',1)->where('order_pay_record.pay_type',8)->select("order_pay_record.order_id","order_pay_record.id")->get();
foreach ($op_arr as $_op) {
	OrderPay::cancel($_op->order_id,$_op->id,0,"service");
}

//取消 当前未完成的 套餐卡销售订单余额支付记录
$op_arr=ServiceCardOrderPayRecord::leftJoin("service_card_order","service_card_order.order_id","=","service_card_order_pay_record.order_id")->where('service_card_order.status',1411)->where('service_card_order_pay_record.status',1)->where('service_card_order_pay_record.pay_type',8)->select("service_card_order_pay_record.order_id","service_card_order_pay_record.id")->get();
foreach ($op_arr as $_op) {
	ServiceCardOrderPayRecord::cancel($_op->order_id,$_op->id,0,"service");
}

//取消 当前未完成的 应收收回的订单余额支付记录
$op_arr=ReceivablePay::leftJoin("receivable","receivable.receivable_id","=","receivable_pay_record.receivable_id")->where('receivable.status',1)->where('receivable.verify_status',0)->where('receivable_pay_record.pay_type',8)->where('receivable_pay_record.status',1)->select("receivable_pay_record.receivable_id","receivable_pay_record.id")->get();
foreach ($op_arr as $_op) {
	Receivable::cancel($_op->receivable_id,$_op->id,0);
}